const constant = require("../../util/constant.js");
const util = require('../../util/util.js');
const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    modalName: null,
    dsrtitle:'当事人姓名',
    dsrhmtitle:'身份证号',
    dsrname:'',
    dsrhm:'',
    dsrzhuzhi:'',
    dsrtel:'',
    daxie:'',//交款金额大写
    fkxx:'',//小写
    fkpjh:'',//罚款票据号
    ajid:0
  },
  
  onLoad:function(option){
    var myuid=wx.getStorageSync('userid');
    //console.log(myuid);
    if(myuid>0)
    {  
        
    }
    else
    {
        wx.redirectTo({
          url: '../login/index',
        })
    }

    var myid=0;
    if(option.id!=null && option.id!="")
    {
        myid=option.id;
    }
    //console.log(myid);
  
    if(myid>0)
    {
        var that=this;
      wx.request({
          url: constant.host+'/appserv/getjz.ashx',
          data: {
            aid:myid,
            k: constant.wkey
          },
          success: function (data) {
              
            var dat = data.data;
            if(dat.length>0)
            {
                var mydata=dat[0];
                let isp=mydata.IsPerson;
                //console.log(myid+'|'+isp);
               
                let dsrhm="";
                if(isp>0)
                {
         
                    dsrhm="身份证号";
                }
                else
                {
                 
                    dsrhm="统一社会信用代码";
                }
    
                
                let afdt=util.formatTime(mydata.AFDate);
               
                
                that.setData({
                    ajid:myid,
                    dsrname:mydata.DSR,
                    dsrhm:mydata.DSRHM,
                    dsrzhuzhi:mydata.DSRAddress,
                    dsrtel:mydata.DSRTel,
                    hourMinuteSecond:afdt,
                    fkxx:mydata.AJCFXX,
                    daxie:mydata.AJCFDX,
                    fkpjh:mydata.AJCFPJH,
                    ajstat:mydata.AJStat,
                    dsrhmtitle:dsrhm
                })
            }
            
          }
        });
    }
    
  },
  
  
  handleSubmit: function (event) {

    var fkpj = event.detail.value.fkpjh;
    if (fkpj == '') {
        util.showFailToast({
          title: '请输入票据号'
        });
  
        return;
      }
    
      var aid=this.data.ajid;
   
    wx.request({
      url: constant.host+'/appserv/uppjh.ashx',
 
      header:{
        //'Content-type':'application/x-www-form-urlencoded'
        'content-type':'application/x-www-form-urlencoded'
      },
      method: "POST",
      data:util.json2Form({
        aid: aid,
        pj:fkpj,
        k:constant.wkey
        //formdata
      }), 
    
      success: function (res) {
          //console.log("r:"+res.data);
          if(res.data>0)
          {
     
            wx.showToast({
              title: "操作成功",
              icon: 'success',
              mask: true,
              duration: 20000,
              success: function (ress) {
                wx.showToast({
                  title: '操作成功',
                })
            
              }

            });
            
      
          }
          else
          {
            util.showFailToast(
              {
                title: "操作失败，请重试"
              }
            )
          }
        
      },
      fail:function(res)
      {
        console.log(res.data)
        util.showFailToast({
          title: "操作失败！请重试"
        });
      }
    });
  },
  dojiean()
  {
      var aid=this.data.ajid;
      wx.showModal({
        title: '结案',
        content: '结案后所有信息将不可修改，确定要结案吗？',
        cancelText: '再看看',
        confirmText: '结案',
        success: res => {
          if (res.confirm) {
            var that=this;
            wx.request({
              url: constant.host+'/appserv/jiean.ashx',
         
              header:{
                //'Content-type':'application/x-www-form-urlencoded'
                'content-type':'application/x-www-form-urlencoded'
              },
              method: "POST",
              data:util.json2Form({
                id: aid,
                k:constant.wkey
                //formdata
              }), 
            
              success: function (res) {
                  //console.log("r:"+res.data);
                  if(res.data>0)
                  {
             
                    wx.showToast({
                      title: "操作成功",
                      icon: 'success',
                      mask: true,
                      duration: 2000,
                      success: function (ress) {
                        that.setData({
                            ajstat:2
                        })
                    
                      }
        
                    });
                    
              
                  }
                  else
                  {
                    util.showFailToast(
                      {
                        title: "操作失败，请重试"
                      }
                    )
                  }
                
              },
              fail:function(res)
              {
                console.log(res.data)
                util.showFailToast({
                  title: "操作失败！请重试"
                });
              }
            });
          }
        }
      })
      
  },
  printview(){
    var aid=this.data.ajid;
    wx.navigateTo({
      url: 'printview?aid='+aid,
    })
  }
})